<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>添加群组</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.STYLE6 {
color:#FFFFFF;
font-size:13px;
}
.STYLE7 {
color:#336699;
font-family:"Arial","宋体";
font-size:12px;
line-height:130%;
}
body {
	background-image: url(images/bg2.gif);
	background-repeat: repeat;
}
</style>
<script src="js/jquery.js"></script>
<script src="js/public.js"></script>
<script type="text/javascript" >
var name="";
$(document).ready(function(){
	if (parent.tmpId != 0) {
		$.post("getGroupByGroupId",
		{'groupId':parent.tmpId},
		function(data){
			var groups = new Array();
			groups = getModelArray(data);
			var group=groups[0];
			name=group.groupName;
			$("#groupName").val(group.groupName);
			$("#describe").val(group.describe);
			$("#groupId").val(group.groupId);
			$("#submit").replaceWith('<input id="submit" type="button" onclick="modGroup()" value="提交"/>');
			if(group.groupName=="我的联系人"){
				$('#groupName').attr("disabled","disabled");
				$("#font1").html("我的联系人为系统默认群组,不能修改名称");
			}else{
				$("#font1").html("<img src=\"images/check_right.gif\"/>");
			}
			parent.tmpId=0;
		},"text")
	}
})
function modGroup() {
	$.post("modGroup",
	{'group.groupId':$("#groupId").val(),
	'group.groupName':$("#groupName").val(),
	'group.describe':$("#describe").val()},
	function(data){
		if(data=="true"){
			window.parent.getGroups();
			window.parent.show_Message("修改群组信息成功!","green");
			window.parent.tb_remove();
		}else{
			window.parent.show_Message("修改群组信息失败!","red");
			window.parent.tb_remove();
		}
	},"text")
}
var timeout;
function checkGroupName(){
	var groupName=window.parent.trim($("#groupName").val());
	groupName=new String(groupName);
	if(groupName.length>0){
		if(groupName==name){
			$("#font1").html("<img src=\"images/check_right.gif\"/>");
			clearTimeout(timeout);
			document.getElementById("submit").disabled=false;
			return;
		}
		groupName=encodeURI(groupName);
		clearTimeout(timeout);
       	timeout = setTimeout(function(){
			$.post("checkExistedGroupName",{'group.groupName':groupName},function(data){
				if(data=="true"){
					$("#font1").attr("color","green");
					$("#font1").html("<img src=\"images/check_right.gif\"/>该群组不存在，可以使用！");
					document.getElementById("submit").disabled=false;
				}else{
					$("#font1").attr("color","red");
					$("#font1").html("<img src=\"images/check_error.gif\"/>&nbsp;该群组已经存在，不能使用！");
					document.getElementById("submit").disabled=true;
				}
			},"text")
		},300);
	}else{
		clearTimeout(timeout);
	}
}

function addGroup(){
	var groupName=$("#groupName").val();
	var describe=$("#describe").val();
	$.post("addGroup",{'group.groupName':groupName,'group.describe':describe},function(data){
		if(data=="true"){
			if(parent.model=="groups"){
				window.parent.changeToGroup();
				window.parent.getGroups();
			}
			window.parent.show_Message("添加群组成功!","green");
			window.parent.tb_remove();
		}else{
			window.parent.show_Message("添加群组失败!","red");
			window.parent.tb_remove();
		}
	},"text")
}
</script> 
</head>
<body>
	<table width="650" border="1" align="center" >
  <tr>
        <td align="right" width="120" bgcolor="#1e84b4" class="STYLE6">组名：</td>
        <td width="250"><input type="text" id="groupName" name="group.groupName"bgcolor="#FFFFFF" class="STYLE7" onKeyUp="checkGroupName()"></input></td>
        <td align="left" width="280"><font id="font1" size="2" color="#808080">请输入用户名</font></td>
    </tr>
     <tr>
        <td align="right" bgcolor="#1e84b4" class="STYLE6">组描述：</td>
        <td><input type="textarea" id="describe" name="group.describe" style="height:80px;width:300px" bgcolor="#FFFFFF" class="STYLE7" /></td>
        <td><font size="2" color="#808080">请输入该组群的描述</font></td>
    </tr>
    <tr >
        <td colspan="2" align="center"><input id="submit" type="button" onClick="addGroup()"  disabled="true" value="提交" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="重置"/></td>
		<td ><img  align="center" src="images/reg1.gif"/><font id="font2" size="2" >请确认</font></td> 
    </tr>
	<input type="hidden" id="groupId" valu="" />
</table>
</body>
</html>
